home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 123_01.zip / SSI.BDS < prev    next >
Text File  |  1993-06-07  |  2KB  |  106 lines

  1. /* Time and date routines for Software Tools
  2.  * source:  date/ssi.bds
  3.  * version: May 1, 1982 - OSCAR GOLDMAN
  4.  * combines date.bds and date/time routines
  5.  * using Godbout System Support I
  6.  */
  7.  
  8. #include tools.h
  9.  
  10. #define    CLOCK_COMM    0x5A        /* command port for the clock */
  11. #define    CLOCK_READ    0x10        /* bias for reading clock */
  12. #define    CLOCK_DATA    0x5B        /* data port */
  13.  
  14. /*    fmtdat - format date and time information from now
  15.  *     which consists of two adjacent string arrays
  16.  *     form is reserved for a format selector.
  17.  *      time is a scratch buffer
  18.  */
  19.  
  20. fmtdat (date, time, now, form)
  21. char *date, *time, *now;
  22. int form;
  23. {
  24.  
  25.     /* copy now to date.  do not copy newline */
  26.     while (*now != NEWLINE && *now != EOS) {
  27.         *date++ = *now++;
  28.     }
  29.     *date = EOS;
  30.  
  31.     *now++;        /* advance past the eos */
  32.     while (*now != NEWLINE && *now != EOS) {
  33.         *time++ = *now++;
  34.     }
  35.     *time = EOS;
  36. }
  37.  
  38.  
  39. /*  getnow - return pointer to current time and date */
  40.  
  41. char *getnow ()
  42. {
  43.     /* put date and time as two adjacent strings */
  44.     /* into sys_date - mmddyyEOShhmmssEOS */
  45.     int k;
  46.     char i[13];
  47.     
  48.     gettod(i);
  49.     for (k=0;k<12;k++) sys_date[k+k/2]=i[k];
  50.     sys_date[2]='/';
  51.     sys_date[5]='/';
  52.     sys_date[8]=EOS;
  53.     sys_date[11]=':';
  54.     sys_date[14]=':';
  55.     sys_date[17]=EOS;
  56.     return(sys_date);
  57. }
  58.  
  59. gettod(i)
  60. char    *i;
  61. {
  62.     /* reads the date and time into i[] */
  63.     /* returns when two successive reads are the same */
  64.  
  65.     char    *tmp;
  66.  
  67.     while (1){
  68.     getdata (tmp);        /* read the clock chip */
  69.     scopy (tmp,0,i,0);
  70.     getdata (tmp);        /* read it again */    
  71.     if (equal (i,tmp)) return;
  72.     }
  73. }
  74.     
  75. getdata (tmp)
  76. char    *tmp;
  77. {
  78.     /* gets the date and time digits in the form */
  79.     /* mmddyyhhmmss as a character string */
  80.  
  81.     int    j,b[12];
  82.     /* b[] contains the order in which the clock digits */
  83.     /* are to be read - it needs to be specified here */
  84.  
  85.     for (j=0;j<12;j++) b[j]=10-j+6*((j+6)/10)-5*(j/6);
  86.  
  87.     for (j=0;j<12;j++) {
  88.     tmp [j]=getdgt (b[j]);
  89.     if (b[j]==5) tmp[j] -=8;
  90.     }
  91.     tmp[12]='\0';
  92. }    
  93.  
  94. getdgt(n)
  95. int    n;
  96.     outp(CLOCK_COMM,CLOCK_READ+n);
  97.     return (inp(CLOCK_DATA)+'0');
  98. }
  99.  
  100. /
  101.     int k;
  102.     char i[13];
  103.     
  104.     gettod(i);
  105.     for (k=0;k<12;k++) sys_date[k+k/2]